package com.ws.game.lesson7.gif
{
	import com.ws.components.loader.ILoader;
	import com.ws.components.loader.LoaderFactory;
	import com.ws.components.player.Animation;
	import com.ws.components.player.FramePlayer;
	import com.ws.game.common.components.SpriteLoader;
	
	import flash.display.Bitmap;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.events.Event;
	
	public class L7 extends SpriteLoader
	{
		var pri:Rigid;
		public function L7()
		{
			super();
		}
		
		override protected function addGameObjects():void{
			var sldr:ILoader = LoaderFactory.createLoader("asset/walk/man.gif");
			sldr.loadUrl(onCallBack);
			
//			var btn:Sprite =new Sprite();
//			this.addEventListener(Event.ENTER_FRAME,onBtnClick);
			this.parent.addEventListener(MouseEvent.CLICK,onBtnClick);
		}
		
		private function onBtnClick(event:Event):void{
			if(pri){
//				trace("Click");
//				pri.moveto(200,500);
//				pri.start();
				pri.addTarget(this.mouseX,this.mouseY);
			}
		}
		
		private function onCallBack(ldr:ILoader):void{
			pri =new Rigid();
			pri.setMoves(ldr.loaderContent);
			
			var sub:Object={};
			sub.x = 200;
			sub.y = 200;
			sub.dx = 1;
			sub.dy = 1;
			
			pri.globalX = 200;
			pri.globalY = 200;
			pri.turn(sub.x+sub.dx,sub.y+sub.dy);
			pri.pass = rolePass;
			this.addChild(pri);
//			pri.moveto(600,200);
			pri.start();
		}
		
		function rolePass(role:Role){
			roadPass(true,role);
		}
		
		function roadPass(v,role:Role){
//			switch(v){
//				//没有障碍时行走
//				case true:
					role.globalX += role.dx;
					role.globalY += role.dy;
					role.x = role.globalX;
					role.y = role.globalY;
//					gameScene.Zaxis(role);
					role.dx = 0;
					role.dy = 0;
					return true;
////					//有障碍时行走
//				case false:
//				default:
//					var dx:Number = role.dx
//					var dy:Number = role.dy;
//					var flag = false;
//					if(dx > 1 || dx < -1){
//						role.dy = 0;
//						flag = gameScene.getRoad(role);
//					}
//					if((dy > 1 || dy < -1) && (flag === undefined || flag !== true)){
//						role.dy = dy;
//						role.dx = 0;
//						flag = gameScene.getRoad(role);
//						
//					}
//					if(flag !== true){
//						role.target.length = 0;
//					}else{
//						role.globalX += role.dx;
//						role.globalY += role.dy;
//						role.x = role.globalX;
//						role.y = role.globalY;
//					}
//					return false;
//			}
		}
	}
}